import tkinter as tk

# 计数排序
def count_sort(arr):
    pos = {}
    minus = {}
    end_k = 0
    start_k = 0
    new_arr = []
    for num in arr:
        num = int(num)
        if num >= 0:
            if num > end_k:
                end_k = num
            pos[num] = pos.get(num, 0) + 1
        else:
            n1 = -num
            if n1 > start_k:
                start_k = n1
            minus[n1] = minus.get(n1, 0) + 1
    for m in range(start_k, 0):
        if m in minus:
            new_arr.extend([-m] * minus[m])
    for p in range(end_k + 1):
        if p in pos:
            new_arr.extend([p] * pos[p])
    return new_arr

# 开始
def send():
    arr_str = entry.get()
    arr = arr_str.split()
    sorted_arr = count_sort(arr)
    result_label.config(text=str(sorted_arr))

# 创建主窗口
root = tk.Tk()
root.title("计数排序")

# 创建输入框和按钮
entry = tk.Entry(root)
entry.insert(0,'1 3 2 5 61 17 9')
entry.pack()
tk.Button(root, text="计数排序", command=send).pack()

# 创建结果标签
result_label = tk.Label(root, text="")
result_label.pack()

# 运行主循环
root.mainloop()